<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>机构表 编辑页面</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <jsp:include page="../com/header.jsp"></jsp:include>
    <script type="text/javascript" src="../../js/comm/editcomm.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#saveOrupdate").click(function () {
                $("#institution_pic").val(imgUrl);
                if (!$('#institutionContent').find('#myImageShow').attr('src')) {
                    myAlert("" +
                        "");
                    return;
                }
                var local_url = $('#fileName').text();
                var web_url = $('#web_url').val();
                if (local_url == '' && web_url == '') {
                    //myAlert("请上传本地视频或填写网络视频地址");
                    //return;
                } else {
                    if (local_url != '') {
                        $('#institution_VideoUrl').val(local_url);
                    }
                    if (web_url != '') {
                        $('#institution_VideoUrl').val(web_url);
                    }
                }
                saveData(root + 'cms/institution/saveInstitution', 'institutionList.jsp');
            });

            var tId = getUrlParam("id");
            if (!tId) {
                myAlert('id参数不能为空');
                return;
            }
            $.ajax({
                url: root + 'cms/institution/findInstitutionById',
                type: 'post',
                dataType: 'json',
                data: {
                    modelId: tId
                },
                success: function (data) {
                    console.log(data);
                    if (data.code == 1) {
                        var contentHtml = $('#institutionTmpl').render(data.object, {
                            mydata: data
                        });

                        $('#institutionContent').html(contentHtml);
                        ue = UE.getEditor("institution_Informations");
                        ue.addListener("ready", function () {
                            if (data.object.institution_Informations)
                                ue.setContent(data.object.institution_Informations);
                        });

                        //视频回填
                        var videoUrl = data.object.institution_VideoUrl;
                        if (!(typeof(videoUrl) == 'undefined' || videoUrl == "")) {
                            if (videoUrl.indexOf('/upload') != -1) {//说明是本地视频
                                $("#fileName").text(videoUrl);
                            } else {
                                $("#web_url").val(videoUrl);
                            }
                        }

                        //城市回填
                        var area = data.object.institution_Area;
                        var defaultCity = data.object.sysAreaId;
                        getCityLists(area, defaultCity);
                    } else {
                        var contentHtml = $('#institutionTmpl').render("");
                        $('#institutionContent').html(contentHtml);
                        //加载城市列表
                        getCityLists();
                    }

                    //机构区域改变的时候，改变城市
                    $("#institution_Area").change(function () {
                        var area = $(this).val();//0,1 国内；国外
                        if (!(typeof(area) == 'undefined' || area == "")) {
                            getCityLists(area)
                        }
                    });
                }
            });

            //上传图片
            $('#institutionContent').on('click', '#uploadPhotoFile', function () {
                upload("institution");
            });
            //上传视频
            $(document).on('change', '#uploadVideoFile', function () {
                console.log("上传视频");
                $.ajaxFileUpload({
                    url: root + 'cms/institution/videoUpload',
                    secureuri: false,
                    fileElementId: 'uploadVideoFile',
                    type: 'POST',
                    dataType: 'json',
                    success: function (data, status) {
                        console.log(data);
                        if (data) {
                            var ds = data.object.split(":");
                            if (ds[0] == 1) {
                                $("#institution_VideoUrl").val(ds[1]);
                                $("#fileName").text(ds[1]);
                                $("#web_url").val(ds[1]);
                            } else {
                                myAlert(ds[1]);
                            }
                        }
                    },
                    error: function (data, status, e) {
                        myAlert(data);
                    }
                });
            });

        });

        function getCityLists(area, defaultCity) {
            var getCityListUrl = root + "cms/sysArea/findSysAreaNEStatusPage";
            var jsonFilter = (typeof(area) == 'undefined' || area == "") ? null : "{'search_EQ_areaType':'" + area + "'}";
            $.ajax({
                url: getCityListUrl,
                data: {
                    nextPage: 0,
                    pageSize: 99999,
                    sortData: null,
                    jsonFilter: jsonFilter
                },
                type: 'POST',
                timeout: 7000,
                dataType: 'json'
            }).done(function (data) {
                if (data.code == 1) {
                    var _html = "<option value='' selected>请选择</option>";
                    for (var i = 0; i < data.object.content.length; i++) {
                        if (data.object.content[i].id == defaultCity) {
                            _html += "<option value='" + data.object.content[i].id + "' selected>" + data.object.content[i].areaName + "</option>";
                        } else {
                            _html += "<option value='" + data.object.content[i].id + "'>" + data.object.content[i].areaName + "</option>";
                        }
                    }
                    $('#sysAreaId').html(_html);
                } else {
                    myAlert(data.message || tipMessage.undefined_msg);
                }
            }).fail(function (jqXHR, textStatus, errorThrown) {
                if (textStatus == "timeout") {
                    myAlert(tipMessage.timeout_msg || "请求超时");
                } else {
                    myAlert(tipMessage.error_msg);
                }
            });
        }

    </script>
</head>
<body>
<section>
    <div>
        <div class="col-xs-12">
            <div class="box" style="height:1200px;">
                <div class="box-header">
                    <br>
                    <input type="button" value="确定" id="saveOrupdate" class="btn btn-success">
                    <input type="button" onclick="backAction('institutionEdit.jsp');" class="btn btn-info" value="返回"/>
                </div>
                <form id="submit_form" class="form-horizontal">
                    <div class="tab" id="institutionContent">
                    </div>
                </form>
            </div>
        </div>
</section>
<script type="text/x-jsrender" id="institutionTmpl">
			<fieldset> 
				<input type="hidden" id="tId" name="id" value="{{:id}}" />
	        	{{!--<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">图片：</label>
       				 <div class="col-md-3">
						<div class="upload_div">
                        	<img id="myImageShow" src="../../{{:imgUrl}}" width="100px" height="100px" />
                        	<input type="hidden" id="imgUrl" name="imgUrl" value="{{:imgUrl}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
                        </div>
					</div>
      			</div>--}}
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">机构名称：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写机构名称" class="form-control input-sm" data-rule="required;length[0~50]" id="institution_Name" name="institution_Name" value="{{:institution_Name}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">组织照片：</label>
       				 <div class="col-md-3">
						<div class="upload_div">
						<img id="myImageShow" src="../../{{:institution_pic}}" width="100px" height="100px" />
                        	<input type="hidden" id="institution_pic" name="institution_pic" value="{{:institution_pic}}"/>
                        	<input type="file" id="uploadPhotoFile" name="photoFile" class="upload_file">
						</div>
					</div>
      			</div>

				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">宣传语：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写宣传语" class="form-control input-sm" data-rule="required;length[0~100]" id="institution_Site" name="institution_Site" value="{{:institution_Site}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">机构电话号码：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写机构电话号码" class="form-control input-sm" data-rule="required;length[0~50]" id="institution_TelPhone" name="institution_TelPhone" value="{{:institution_TelPhone}}" />
					</div>
      			</div>

				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">机构地址：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写机构地址" class="form-control input-sm" data-rule="required;length[0~255]" id="institution_address" name="institutionAddress" value="{{:institutionAddress}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">参观价格：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写机构参观价格" class="form-control input-sm" data-rule="required;length[0~50]" id="institution_Price" name="institution_Price" value="{{:institution_Price}}" />
					</div>
      			</div>
      			<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">机构区域：</label>
       				 <div class="col-md-1">
							<select class="form-control input-sm" id="institution_Area" name="institution_Area">
									    		<option value="">请选择</option>
									    		<option value="0" {{if institution_Area==0}}selected{{/if}}>国内</option>
									    		<option value="1" {{if institution_Area==1}}selected{{/if}}>国外</option>
							</select>
					 </div>
					  <div class="col-md-1">
							<select class="form-control input-sm" id="sysAreaId" name="sysAreaId" data-rule="required">
									    <option value="">请选择</option>
							</select>
					 </div>
      			</div>
				<%--<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">视频链接：</label>
       				 <div class="col-md-3">
						<input type="text" placeholder="请填写视频链接" class="form-control input-sm" data-rule="required;length[0~255]" id="institution_VideoUrl" name="institution_VideoUrl" value="{{:institution_VideoUrl}}" />
					</div>
      			</div>--%>
				<div class="form-group" style="height: 80px;">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">视频链接：</label>
					<div class="col-md-4">
					<div class="bs-example-tabs"  >
						<ul id="myTab" class="nav nav-tabs" role="tablist">
      						<li role="presentation" class="active"><a href="#home" id="home-tab" role="tab" data-toggle="tab" aria-controls="home" aria-expanded="true">本地视频</a></li>
      						<li role="presentation"><a href="#profile" role="tab" id="profile-tab" data-toggle="tab" aria-controls="profile">网络视频</a></li>
    					</ul>
						<div id="myTabContent" class="tab-content">
							<div role="tabpanel" class="tab-pane fade in active col-md-10" id="home" aria-labelledBy="home-tab">
								<label >视频文件：</label><br/>
								<input type="file" id="uploadVideoFile" name="videoFile" style="width: 67px;" >
								<span id="fileName"></span>
      							<input type="hidden" id="local_url" name="local_url" value="{{:institution_VideoUrl}}"/>
							</div>
							<div role="tabpanel" class="tab-pane fade col-md-10" id="profile" aria-labelledBy="profile-tab">
      							<label for="formGroupInputSmall">视频网址：</label><br/>
								<input type="text" placeholder="请填写视频网址" class="form-control input-sm"  id="web_url" name="web_url"/>
								<input type="hidden" id="institution_VideoUrl" name="institution_VideoUrl" value="{{:institution_VideoUrl}}"/>
							</div>
						</div>
					</div>
					</div>
      			</div>
      			<br/>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">机构类型：</label>
								<div class="col-md-3">
       				 			     <select class="form-control input-sm" id="search_institution_type" name="institution_type">
									    		<option value="">请选择</option>
									    		<option value="0" {{if institution_type==0}}selected{{/if}}>享老居所</option>
									    		<option value="1" {{if institution_type==1}}selected{{/if}}>旅游居所</option>
									    		<option value="2" {{if institution_type==2}}selected{{/if}}>养护院</option>
									</select>
								 </div>
      			</div>
      			<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">排序值：</label>
       				 <div class="col-md-4">
						<input type="text" placeholder="请填写排序值" class="form-control input-sm" data-rule="length[1~10];plus" maxlength="10" id="sort" name="sort" value="{{:sort}}" />
					</div>
      			</div>
				<div class="form-group">
        			<label class="col-md-2 control-label controls" for="formGroupInputSmall">机构介绍 ：</label>
       				 <div class="col-md-3">
						<!-- <input type="text" placeholder="请填写机构介绍" class="form-control input-sm" data-rule="required;" id="institution_Informations" name="institution_Informations" value="{{:institution_Informations}}" />-->
						<div  id="institution_Informations" name="institution_Informations" style="height:200px;width:760px"></div>
					</div>
      			</div>
			</fieldset>

</script>
</body>
</html>